package office.action.business;

import java.util.List;

import office.action.business.form.ContractConditionForm;
import office.action.business.form.ContractProductDetailConditionForm;
import office.action.business.form.ContractProductDetailForm;
import office.action.business.wrapper.ContractProductDetailWrapper;
import office.action.business.wrapper.ContractWrapper;
import office.service.business.IContractProductDetailService;
import office.service.business.IContractService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;

/**
 * 
 * 标书对应的产品
 * 
 * @author ZhangYQ
 * 
 */
public class ContractProductDetailAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private IContractProductDetailService contractProductDetailService;
	private IContractService contractService;
	private Page page; // 分页信息
	private List<ContractProductDetailWrapper> wrapperList;
	private List<ContractWrapper> contractWrapperList;
	private ContractProductDetailForm form;
	private ContractProductDetailConditionForm condition;
	private ContractConditionForm contractCondition;
	private String id;

	/**
	 * 获取所有的产品以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllContractProductDetail() throws Exception {
		page = contractProductDetailService.getPageInfo(condition);
		wrapperList = contractProductDetailService.findAllContractProductDetail(condition,page);
		if(condition!=null){
			return "listContractProductDetailByPage";
		}
		return "findAllContractProductDetail";
	}

	/**
	 * 初始化编辑产品页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditContractProductDetail() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = contractProductDetailService.getById(id);
		}
		contractWrapperList=contractService.findAllContractByStatus(contractCondition);
		return "gotoEditContractProductDetail";
	}

	/**
	 * 编辑产品
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editContractProductDetail() throws Exception {
		try {
			contractProductDetailService.editContractProductDetail(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询产品结构
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listContractProductDetailByPage() throws Exception {
		try {
			wrapperList = contractProductDetailService.findAllContractProductDetail(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listContractProductDetailByPage";
	}

	/**
	 * 初始化产品结构列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoContractProductDetailMenu() throws Exception {
		return "gotoContractProductDetailMenu";
	}

	/**
	 * 跳转到产品删除确认页面
	 */
	public String gotoDeleteContractProductDetail(){
		return "gotoDeleteContractProductDetail";
	}
	
	/**
	 * 删除产品
	 * @return
	 * @throws Exception
	 */
	public String delContractProductDetail() throws Exception {
		try {
			contractProductDetailService.delContractProductDetailById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 
	 * <br/>
	 * 方法描述:根据标书获取表苏对应的产品明细
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listContractProductDetailByContractId() throws Exception {
		try {
			wrapperList = contractProductDetailService.findAllContractProductDetailByContractId(condition);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listContractProductDetailByContractId";
	}
	
	public IContractProductDetailService getContractProductDetailService() {
		return contractProductDetailService;
	}

	public void setContractProductDetailService(IContractProductDetailService contractProductDetailService) {
		this.contractProductDetailService = contractProductDetailService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<ContractProductDetailWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<ContractProductDetailWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public ContractProductDetailForm getForm() {
		return form;
	}

	public void setForm(ContractProductDetailForm form) {
		this.form = form;
	}

	public ContractProductDetailConditionForm getCondition() {
		return condition;
	}

	public void setCondition(ContractProductDetailConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public IContractService getContractService() {
		return contractService;
	}

	public void setContractService(IContractService contractService) {
		this.contractService = contractService;
	}

	public ContractConditionForm getContractCondition() {
		return contractCondition;
	}

	public void setContractCondition(ContractConditionForm contractCondition) {
		this.contractCondition = contractCondition;
	}

	public List<ContractWrapper> getContractWrapperList() {
		return contractWrapperList;
	}

	public void setContractWrapperList(List<ContractWrapper> contractWrapperList) {
		this.contractWrapperList = contractWrapperList;
	}
	
	
}
